package com.upc.tp.timeplanning.mapper;

import com.upc.tp.timeplanning.entity.Rule;
import com.upc.tp.timeplanning.entity.Task;
import org.apache.ibatis.annotations.*;


import java.util.List;


@Mapper
public interface RuleMapper {

    @Select("SELECT * FROM rule")
    List<Rule> getAll();

    @Select("SELECT * FROM rule WHERE stu_username = #{stu_username} OR stu_username = 'all' ")
    List<Rule> getByStuUsername(@Param("stu_username")String stu_username);

    @Select("SELECT * FROM rule WHERE par_username = #{par_username} OR par_username = 'all' ")
    List<Rule> getByParUsername(@Param("par_username")String par_username);

    @Select("SELECT * FROM rule WHERE rule_id = #{rule_id}")
    Rule getCycle(@Param("rule_id")Integer rule_id);

    @Select("SELECT * FROM rule WHERE rule_id = #{rule_id}")
    List<Rule> getById(@Param("rule_id")Integer rule_id);

    @Insert("INSERT INTO rule(stu_username,par_username,rule_name,cycle) VALUES(#{stu_username},#{par_username},#{rule_name},#{cycle})")
    int makeRule(@Param("stu_username")String stu_username, @Param("par_username")String par_username, @Param("rule_name")String rule_name, @Param("cycle")Integer cycle);

    @Delete("DELETE FROM rule WHERE rule_id = #{rule_id}")
    int delete(@Param("rule_id")Integer rule_id);
}
